#ifndef RESIZABLERECTSCENE_H
#define RESIZABLERECTSCENE_H

#include <QGraphicsScene>
#include <QPointF>

class ResizableRectItem;

class ResizableRectScene : public QGraphicsScene
{
    Q_OBJECT
public:
    explicit ResizableRectScene(QObject *parent = nullptr);

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;

private:
    // 判断位置是否在指定项的内部
    bool isPointInItem(QGraphicsRectItem* targetItem,const QPointF& scenePos);

private:
    bool m_leftButtonDrawing;
    bool m_rightButtonDrawing;
    QPointF m_startPoint;
    ResizableRectItem *m_currentRect;
    ResizableRectItem* m_leftRect;
    ResizableRectItem* m_rightRect;

    // 找到包含给定点的最顶层左键矩形
    ResizableRectItem* findParentLeftRect(const QPointF &pos);
};

#endif // RESIZABLERECTSCENE_H
